<template>
  <div class="comment-audit-status-bg">
    <el-card class="comment-audit-status-card">
      <div class="comment-audit-status-header">
        <el-button @click="goBack" icon="ArrowLeft">返回</el-button>
        <div class="comment-audit-status-title">评论审核状态</div>
      </div>
      
      <div class="search-section">
        <el-form :model="searchForm" inline>
          <el-form-item label="评论ID">
            <el-input 
              v-model="searchForm.comment_id" 
              placeholder="请输入评论ID"
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="searchAuditStatus" :loading="loading">
              查询状态
            </el-button>
          </el-form-item>
        </el-form>
      </div>
      
      <div v-if="auditResult" class="audit-result">
        <el-descriptions :column="1" border title="审核结果">
          <el-descriptions-item label="评论ID">{{ auditResult.comment_id }}</el-descriptions-item>
          <el-descriptions-item label="AI决策">
            <el-tag :type="getDecisionType(auditResult.ai_decision)">
              {{ getDecisionText(auditResult.ai_decision) }}
            </el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="审核时间">{{ formatTime(auditResult.audit_time) }}</el-descriptions-item>
          <el-descriptions-item label="审核方法">{{ auditResult.audit_method }}</el-descriptions-item>
        </el-descriptions>
        
        <!-- 文本审核结果 -->
        <div v-if="auditResult.text_audit" class="audit-detail">
          <h4>文本审核详情</h4>
          <el-descriptions :column="1" border>
            <el-descriptions-item label="审核决策">
              <el-tag :type="getDecisionType(auditResult.text_audit.audit_decision)">
                {{ getDecisionText(auditResult.text_audit.audit_decision) }}
              </el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="敏感词">{{ auditResult.text_audit.sensitive_words || '无' }}</el-descriptions-item>
            <el-descriptions-item label="审核原因">{{ auditResult.text_audit.reason }}</el-descriptions-item>
            <el-descriptions-item label="置信度">{{ auditResult.text_audit.confidence }}%</el-descriptions-item>
          </el-descriptions>
        </div>
        
        <!-- 图片审核结果 -->
        <div v-if="auditResult.image_audit" class="audit-detail">
          <h4>图片审核详情</h4>
          <el-descriptions :column="1" border>
            <el-descriptions-item label="审核决策">
              <el-tag :type="getDecisionType(auditResult.image_audit.audit_decision)">
                {{ getDecisionText(auditResult.image_audit.audit_decision) }}
              </el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="违规类型">{{ auditResult.image_audit.violation_type || '无' }}</el-descriptions-item>
            <el-descriptions-item label="审核原因">{{ auditResult.image_audit.reason }}</el-descriptions-item>
            <el-descriptions-item label="置信度">{{ auditResult.image_audit.confidence }}%</el-descriptions-item>
          </el-descriptions>
        </div>
        
        <!-- 综合结果 -->
        <div class="audit-summary">
          <h4>综合审核结果</h4>
          <el-alert
            :title="getSummaryTitle(auditResult.ai_decision)"
            :type="getSummaryType(auditResult.ai_decision)"
            :description="getSummaryDescription(auditResult.ai_decision)"
            show-icon
            :closable="false"
          />
        </div>
      </div>
      
      <div v-else-if="!loading && !searchForm.comment_id" class="no-search">
        <el-empty description="请输入评论ID查询审核状态" />
      </div>
      
      <div v-else-if="!loading && searchForm.comment_id && !auditResult" class="no-result">
        <el-empty description="未找到该评论的审核信息" />
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { commentAPI } from '@/api/order'

const router = useRouter()
const searchForm = ref({
  comment_id: ''
})
const loading = ref(false)
const auditResult = ref(null)

function goBack() {
  router.go(-1)
}

function formatTime(time) {
  if (!time) return '--'
  return new Date(time).toLocaleString('zh-CN')
}

function getDecisionType(decision) {
  switch (decision) {
    case 'pass': return 'success'
    case 'reject': return 'danger'
    case 'pending': return 'warning'
    default: return 'info'
  }
}

function getDecisionText(decision) {
  switch (decision) {
    case 'pass': return '通过'
    case 'reject': return '拒绝'
    case 'pending': return '待审核'
    default: return '未知'
  }
}

function getSummaryType(decision) {
  switch (decision) {
    case 'pass': return 'success'
    case 'reject': return 'error'
    case 'pending': return 'warning'
    default: return 'info'
  }
}

function getSummaryTitle(decision) {
  switch (decision) {
    case 'pass': return 'AI审核通过'
    case 'reject': return 'AI审核拒绝'
    case 'pending': return 'AI审核中'
    default: return '审核状态未知'
  }
}

function getSummaryDescription(decision) {
  switch (decision) {
    case 'pass': return '评论内容符合规范，已存入数据库，可在司机评论列表中查看。'
    case 'reject': return '评论内容包含敏感信息，已被驳回，不会在司机评论列表中显示。'
    case 'pending': return '评论正在接受AI审核，请稍后查询。'
    default: return '审核状态异常，请联系管理员。'
  }
}

async function searchAuditStatus() {
  if (!searchForm.value.comment_id) {
    ElMessage.warning('请输入评论ID')
    return
  }
  
  try {
    loading.value = true
    auditResult.value = null
    
    const response = await commentAPI.getCommentAuditStatus(searchForm.value.comment_id)
    
    if (response.code === 200) {
      auditResult.value = response.data
      ElMessage.success('查询成功')
    } else {
      ElMessage.error(response.message || '查询失败')
    }
  } catch (error) {
    console.error('查询审核状态失败:', error)
    ElMessage.error('查询失败，请稍后重试')
  } finally {
    loading.value = false
  }
}
</script>

<style scoped>
.comment-audit-status-bg {
  min-height: 100vh;
  background: linear-gradient(135deg, #fff 60%, #e6f7ff 100%);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
}

.comment-audit-status-card {
  width: 100%;
  max-width: 800px;
  border-radius: 18px;
  box-shadow: 0 4px 24px 0 rgba(34,34,34,0.08);
  padding: 32px 36px 24px 36px;
  position: relative;
}

.comment-audit-status-header {
  display: flex;
  align-items: center;
  margin-bottom: 24px;
}

.comment-audit-status-title {
  font-size: 26px;
  font-weight: bold;
  color: #222;
  text-align: center;
  margin: 0 auto;
  letter-spacing: 2px;
}

.search-section {
  margin-bottom: 24px;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 8px;
}

.audit-result {
  margin-top: 20px;
}

.audit-detail {
  margin-top: 20px;
}

.audit-detail h4 {
  margin-bottom: 12px;
  color: #333;
  font-size: 16px;
  font-weight: 600;
}

.audit-summary {
  margin-top: 20px;
}

.audit-summary h4 {
  margin-bottom: 12px;
  color: #333;
  font-size: 16px;
  font-weight: 600;
}

.no-search,
.no-result {
  text-align: center;
  padding: 40px 20px;
}
</style> 